{extend name="public:layout" /}
{block name="title"}{$moudleName}列表{/block}
{block name="head"}{/block}
{block name="body"}
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <ol class="breadcrumb">
                    <li class="active"><i class="fa fa-hand-o-right"></i> {$moudleName}列表</li>
                </ol>
            </ol>
        </div>
        <div class="ibox-content">
            <div class="toolbar">
                <form class="form-inline" id="searchForm" method="post">
                    <div class="form-group">
                        <div class="input-group">
                            <input class="form-control" type="text" placeholder="请输入车牌号" name="car_sn" />
                        </div>
                    </div>
                    <button type="button" class="btn btn-info" onclick="refresh()"><i class="fa fa-search"></i> 搜索</button>
                    <a class="btn btn-white" href="{:url('index',['mid'=>$Request.param.mid])}">
                        <i class="fa fa-trash"></i> 清空
                    </a>
                </form>
            </div>
            <div id="buttons">
                <button type="button" onclick="add();" class="btn btn-primary">
                    <i class="fa fa-sort"></i> 添加{$moudleName}
                </button>
                <button type="button" onclick="upOrder();" class="btn btn-info">
                    <i class="fa fa-sort"></i> 排序
                </button>
                <button type="button" onclick="batchDel(CheckboxValue())" class="btn btn-danger">
                    <i class="fa fa-trash"></i> 删除
                </button>
            </div>
            <table class="table table-bordered" id="grid"></table>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        //列定义
        var columnsData=[
            {field: 'state', checkbox:true,},
            {field: 'aid', width:80, sortable:true, title: '编号'},
            {field: 'safe_year', width:80, sortable:true, title: '年度'},
            {field: 'car_sn_text', title: '车牌号'},
            {field: 'safe_time', title: '投保时间'},
            {field: 'safe_endtime', title: '到期时间'},
            {field: 'surplus', title: '剩余天数'},
            {field: 'safe_type', title: '投保种类'},
            {field: 'safe_money', title: '投保金额'},
            {field: 'operate', title: '操作', width:200, align: 'center',
                formatter:function (value,row,index) {
                    if(row.surplus>45){
                        var html='<a href="__URL__/edit.html?aid='+row.aid+'&mid='+row.mid+'" class="btn btn-success btn-xs">编辑</a> ';
                        html+='<a href="javascript:;" onclick="doAction(this,refresh);"\n' +
                            '                           data-msg="确认删除吗？" data-url="__URL__/del.html" data-params="aid='+row.aid+'&mid='+row.mid+'" class="btn btn-danger btn-xs">删除</a>';

                    }else{
                        var html='<a href="__URL__/edit.html?aid='+row.aid+'&mid='+row.mid+'" class="btn btn-success btn-xs">编辑</a> ';
                        html+='<a href="javascript:;" onclick="doAction(this,refresh);"\n' +
                            '                           data-msg="确认删除吗？" data-url="__URL__/del.html" data-params="aid='+row.aid+'&mid='+row.mid+'" class="btn btn-danger btn-xs">删除</a>';
                        if(row.is_renewal==0){
                            html+='&nbsp;&nbsp;<a href="__URL__/edit.html?tpl=renewal_safe&aid='+row.aid+'&mid='+row.mid+'" class="btn btn-warning btn-xs">续保</a> ';
                        }
                    }
                    return html;
                }
            }
        ];
        initTable('/system/logic.query/safelist.html?mid={$Request.param.mid}',columnsData,function (params) {
            params.op="{$Request.param.op}";
            params.car_sn=$("input[name='car_sn']").val();
            return params;
        })
    });
    //刷新表格
    function refresh() {
        $('#grid').bootstrapTable('refresh');
    }
    //添加
    function add() {
        var mid="{$Request.param.mid}";
        location.href="__URL__/add.html?mid="+mid;
    }
    //批量删除文章
    function batchDel(aid) {
        if (IsMore(aid)) {
            var url = "{:url('del')}";
            var params = {'aid': aid, 'mid': "{$Request.param.mid}"};
            doConfirm('你确认要删除吗？', url, params, function (data) {
                if (data.code == 1) {
                    rePage();
                }
            });
        }
    }
    //更新排序
    function upOrder() {
        if ($(".batchSort").length == 0) {
            alert('您还没有添加内容！');
            return false;
        }
        var params = $(".batchSort").serialize();
        var url = "__URL__/uporder.html?mid={$Request.param.mid}";
        getAjax(url, params, function (data) {
            if (data.code == 1) {
                rePage();
            }
        });
    }
</script>
{/block}